//index.js
import http from "../../../class/Utils/Http"
import tips from "../../../class/Utils/Tips"
import user from "../../../class/Utils/User"

Page({
    data: {
        list:[],
        nodata:false
    },
    onLoad: function () {
        var that = this
        var user = wx.getStorageSync('user')
        var data = {
            uid:user.userid
        }
        http.req("/Api/shangji_list",data,function (res) {
            console.log(res)
            that.setData({
                list:res.list
            })
            if(res.pw_rec_total == 0){
                that.setData({
                    nodata:true
                })
            }
        })
    },
    /*
    删除商机
     */
    del:function (e) {
        var that = this
        var user = wx.getStorageSync("user")
        var id = e.currentTarget.dataset.id
        var index = e.currentTarget.dataset.index
        var list = that.data.list
        tips.modal("是否删除该商机",true,'function',false,function () {
            var data = {
                uid:user.userid,
                id:id
            }

            http.req("/Api/shangji_del",data,function (res) {
                if (res.code == '207') {
                    tips.ok(res.msg_val)
                    list.splice(index, 1);
                    if (list.length == 0) {
                        that.setData({
                            nodata: true
                        })
                    }
                    that.setData({
                        list
                    })
                } else {
                    tips.error(res.msg_val)
                }
            })
        })
    }
})
